package com.sptpc.demo1.controller;

import com.sptpc.demo1.model.Category;
import com.sptpc.demo1.model.Drink;
import com.sptpc.demo1.model.Student;
import com.sptpc.demo1.service.ICategoryService;
import com.sptpc.demo1.service.IDrinkService;
import com.sptpc.demo1.service.IStudentService;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDate;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public IStudentService studentService;
    @Autowired
    public ICategoryService categoryService;


    //登录首页
    @GetMapping("/")
    public String Index(){
        return "manage/login";
    }
    //首页
    @GetMapping("/manage/index")
    public String Indexs(){
        return "manage/index";
    }
    //欢迎界面
    @GetMapping("/manage/welcome")
    public String welcome(){
        return "manage/welcome";
    }




    //饮品管理界面
    @GetMapping("/menu/drink")
    public String drink(){
        return "drink/index";
    }
    //添加饮品
    @GetMapping("/drink/addform")
    public String adddrink(){
        return "/drink/add";
    }
    //饮品修改
    //get /drink/updatafrom?id=1
    @GetMapping("/drink/updateform")
    public ModelAndView updatedeleteFrom(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("drink/edit");
        Drink drink=drinkService.getDrinkById(id);
        //ToDD:从数据库中查询出对应的商品信息
        mv.addObject("data",drink);
        return mv;
    }


    //学生管理界面
    @GetMapping("/menu/student")
    public String student(){
        return "student/index";
    }
    //添加学生
    @GetMapping("/student/addform")
    public String addstudent(){
        return "/student/add";
    }
    //修改学生
    //get /drink/updatafrom?id=1
    @GetMapping("/student/updateform")
    public ModelAndView updateDeleteStudent(@RequestParam Long id){
        ModelAndView mv = new ModelAndView("student/edit");
        //ToDD:从数据库中查询出对应的商品信息
        Student student=studentService.getStudnetById(id);
        mv.addObject("data",student);
        return mv;
    }

    //分类管理
    @GetMapping("/menu/category")
    public String categoryIndex(){
        return "category/index";
    }
    //新增
    @GetMapping("/category/addform")
    public String adddcategory(){
        return "category/add";
    }
    //分类修改
    @GetMapping("/category/updateform")
    public ModelAndView updatedeleteCategory(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("category/edit");
        Category category=categoryService.getCategoryById(id);
        //ToDD:从数据库中查询出对应的商品信息
        mv.addObject("data",category);
        return mv;
    }

    //分类管理
    @GetMapping("/menu/order")
    public String orderIndex(){
        return "order/index";
    }


}